<?php 
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../../value/value_en.php";
} else if($lang == "VN") {
	include "../../value/value_vn.php";
}
else {
	include "../../value/value_kr.php";
}
include '../../operations/connection.php';
include '../../generallibraries/funcs.php';
$_SESSION['thongbao_employee_salary']="";
if(isset($_SESSION['emsa'])){
	if(isset($_REQUEST['thang']) && isset($_REQUEST['nam'])){
		if($_REQUEST['thang']!="" && $_REQUEST['nam'] && count($_SESSION['emsa'])>0){
			$idlog=$_REQUEST['nam']."-".$_REQUEST['thang'];
			$ktquery="SELECT sa_employee_salary_log.idlog 
			from sa_employee_salary_log 
			where sa_employee_salary_log.idlog='".$idlog."' and sa_employee_salary_log.is_saved=1";
			$m=mysql_query($ktquery);
			if(mysql_num_rows($m)>0){
				$_SESSION['thongbao_employee_salary']="l_payroll_not_caculate_again";
			}else{
				$s1="insert INTO sa_employee_salary (employeeID,sa_time,number_time_work,basic_salary,allowance_basic_salary,number_dateoff,number_holiday,number_is_comeback_early,number_is_late,allowance_senior,allowance_c,oneday_salary,paid_salary,allowance_holiday,allowance_lunch,allowance_car,allowance_hard,number_overtime,overtime_salary,total_salary,insurance,received_salary,salary_bornus,salary_sub,note,is_saved,user_create,createDate,is_sendmail,really_number_time_work,number_allow_holiday) ";
				$s2="";
				$mang=$_SESSION['emsa'];
				foreach($mang as $khoa=>$t){
					if($s2==""){
						$s2 =" values ('".$t[employeeID]."','".$idlog."',".$t[number_time_work].",".$t[basic_salary].",".$t[allowance_basic_salary].",".$t[number_dateoff].",".$t[number_holiday].",".$t[number_is_comeback_early].",".$t[number_is_late].",".$t[allowance_senior].",".$t[allowance_c].",".$t[oneday_salary].",".$t[paid_salary].",".$t[allowance_holiday].",".$t[allowance_lunch].",".$t[allowance_car].",".$t[allowance_hard].",".$t[number_overtime].",".$t[overtime_salary].",".$t[total_salary].",".$t[insurance].",".$t[received_salary].",".$t[salary_bornus].",".$t[salary_sub].",'".$t[note]."',1,'".$_SESSION['IDEmployee']."',now(),0,".$t[really_number_time_work].",".$t[number_allow_holiday].")";
					}else{
						$s2 .=",('".$t[employeeID]."','".$idlog."',".$t[number_time_work].",".$t[basic_salary].",".$t[allowance_basic_salary].",".$t[number_dateoff].",".$t[number_holiday].",".$t[number_is_comeback_early].",".$t[number_is_late].",".$t[allowance_senior].",".$t[allowance_c].",".$t[oneday_salary].",".$t[paid_salary].",".$t[allowance_holiday].",".$t[allowance_lunch].",".$t[allowance_car].",".$t[allowance_hard].",".$t[number_overtime].",".$t[overtime_salary].",".$t[total_salary].",".$t[insurance].",".$t[received_salary].",".$t[salary_bornus].",".$t[salary_sub].",'".$t[note]."',1,'".$_SESSION['IDEmployee']."',now(),0,".$t[really_number_time_work].",".$t[number_allow_holiday].")";
					}
				}
				$s2 = $s1." ".$s2;
				if($s2 !=""){
					mysql_query($s2);
					$sql="INSERT INTO sa_employee_salary_log (idlog,date_create,user_create,is_saved) 
					values ('".$idlog."',now(),'".$_SESSION['IDEmployee']."',1)";
					mysql_query($sql);
					
					$sql="update sa_check_time set sa_check_time.`status`=2 
					where MONTH(sa_check_time.time_work)='".$_REQUEST['thang']."' 
					and YEAR(sa_check_time.time_work)='".$_REQUEST['nam']."' 
					and sa_check_time.`status`!=1";
					mysql_query($sql);
					
					/*$sql="update sa_check_time_log set sa_check_time_log.is_status=1, 
					sa_check_time_log.updateUser='".$_SESSION['IDEmployee']."', 
					sa_check_time_log.updateDate=now() 
					where sa_check_time_log.id='".$idlog."'";
					mysql_query($sql);*/
					
					$_SESSION['thongbao_employee_salary']="l_payroll_saved";
				}
			}
		}
	}
}
?>
<div style="width:100%;align:center;">
	<input type="hidden" name="viewthongbao" id="viewthongbao" value="<?php echo $_SESSION['thongbao_employee_salary'];?>" />
</div>
<?php mysql_close($connection);?>